package com.springmvc.xml;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;

/**
 * xml解析器
 */
public class XmlPaser {

    public static String getBasePackage(String xml){
        try {
            SAXReader saxReader = new SAXReader();
            InputStream inputStream = XmlPaser.class.getClassLoader().getResourceAsStream(xml);
            // Xml文件对象
            Document document = saxReader.read(inputStream);
            Element rootElement = document.getRootElement();
            Element element = rootElement.element("component-scan");
            Attribute attribute = element.attribute("base-package");
            return attribute.getText();
        } catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }


}
